package cn.topevery.garden.dal.logic.warning;

import cn.topevery.garden.dal.logic.base.WarningBase;
import cn.topevery.garden.entity.dto.RubbishBinReportDTO;
import hw.topevery.basis.dal.logic.SysClassExtLogic;
import hw.topevery.basis.entity.po.SysClassExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ：peng.tian
 * @date ：Created in 2021/10/28 21:20
 * @description：
 */
@Component
public class RubbishBinWarning extends WarningBase {
    @Override
    public String getClassId() {
        return "70C0BE95-2345-4D94-ABA9-E40DEE4D4AEA";
    }

    @Override
    public String getFacilitiesType() {
        return "d408daf6-1fc9-49a8-9927-ba53ff07a9f3";
    }

    @Override
    public String getWarningType() {
        return "46D152EA-8122-4D4C-90E8-8FDEA428A703";
    }

    @Autowired
    private SysClassExtLogic sysClassExtLogic;

    public void check(RubbishBinReportDTO dto) {
        StringBuilder warningDesc = new StringBuilder();
        SysClassExt transform = sysClassExtLogic.getEntityByDataId("19CBCCE1-6AEF-4C21-8402-8689332EDB1C");
        SysClassExt brimOverHeight = sysClassExtLogic.getEntityByDataId("B4F579C1-EDAA-4681-B5F3-5615D0CE6BAE");
        SysClassExt electricity = sysClassExtLogic.getEntityByDataId("9F59E344-6408-4A0A-A081-CD7E116542BA");
        boolean isWarning = false;
        if (dto.getAngle() > Integer.parseInt(transform.unit)) {
            isWarning = true;
            warningDesc.append("垃圾桶位置异常报警，垃圾桶倾斜角度大于").append(dto.getAngle()).append("度\n");
            this.setSmallClassId("19CBCCE1-6AEF-4C21-8402-8689332EDB1C");
        }
        if (dto.getBrimOverHeight() != null && dto.getBrimOverHeight() < Integer.parseInt(brimOverHeight.unit)) {
            isWarning = true;
            warningDesc.append("垃圾满溢报警，传感器垃圾高度低于").append(dto.getBrimOverHeight()).append("cm\n");
            this.setSmallClassId("B4F579C1-EDAA-4681-B5F3-5615D0CE6BAE");
        }
        if (dto.getElectricity() != null && dto.getElectricity() < Integer.parseInt(electricity.unit)) {
            isWarning = true;
            warningDesc.append("设备低电报警，电压低于").append(dto.getElectricity()).append("V");
            this.setSmallClassId("9F59E344-6408-4A0A-A081-CD7E116542BA");
        }
        if (isWarning) {
            sendWarning(dto.getDeviceCode(), warningDesc.toString(), dto.getId());
        }
    }
}
